package com.crl.gen.dao;

import com.crl.dao.BaseDao;
import com.crl.gen.model.GenTable;
import com.crl.gen.vo.GenTableSearchVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/22 23:02
 */
@Repository
public class GenTableDao extends BaseDao<GenTable, GenTableSearchVO> {

    /**
     * 新增
     *
     * @param genTable
     * @return
     */
    public int add(GenTable genTable) {
        String sql = "INSERT INTO td_gen_table(author_id,tablename,description,java_package,is_page,is_add,is_delete,is_update,is_view,first_code,second_code,first_name,second_name,pk_create,pk_field,order_field,api_url) " +
                "VALUES(:authorId,:tablename,:description,:javaPackage,:isPage,:isAdd,:isDelete,:isUpdate,:isView,:firstCode,:secondCode,:firstName,:secondName,:pkCreate,:pkField,:orderField,:apiUrl)";
        return insert(sql, genTable);
    }


    /**
     * 修改
     *
     * @param genTable
     * @return
     */
    public int update(GenTable genTable) {
        String sql = "UPDATE td_gen_table SET  tablename=:tablename,description=:description,java_package=:javaPackage,is_page=:isPage,is_add=:isAdd,is_delete=:isDelete," +
                "is_update=:isUpdate,is_view=:isView,first_code=:firstCode,second_code=:secondCode,first_name=:firstName,second_name=:secondName,pk_create=:pkCreate,pk_field=:pkField,order_field=:orderField,api_url=:apiUrl WHERE id=:id";
        return update(sql, genTable);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(int id) {
        String sql = "DELETE FROM td_gen_table WHERE id=?";
        return delete(sql, id);
    }


    /**
     * 列表
     *
     * @return
     */
    public List<GenTable> list(int authorId) {
        String sql = "SELECT id,author_id,tablename,description,java_package,is_page,is_add,is_delete,is_update,is_view,first_code,second_code,first_name,second_name,pk_create,pk_field,order_field,api_url FROM td_gen_table WHERE author_id=? ";
        sql += " ORDER BY id ASC";
        return list(sql, authorId);
    }

    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public GenTable get(int id) {
        String sql = "SELECT id,author_id,tablename,description,java_package,is_page,is_add,is_delete,is_update,is_view,first_code,second_code,first_name,second_name,pk_create,pk_field,order_field,api_url FROM td_gen_table WHERE id=?";
        return get(sql, id);
    }

}
